package com.ruoyi.web.controller.organization;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.organization.domain.vo.CommunityScore;
import com.ruoyi.organization.domain.vo.CommunityScoreDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.organization.domain.BizFamilyScoreLog;
import com.ruoyi.organization.service.IBizFamilyScoreLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 家庭积分流水明细Controller
 * 
 * @author ruoyi
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/organization/familyScoreLog")
public class BizFamilyScoreLogController extends BaseController
{
    @Autowired
    private IBizFamilyScoreLogService bizFamilyScoreLogService;

    /**
     * 查询家庭积分流水明细列表
     */

    @PreAuthorize("@ss.hasPermi('organization:family:query')")
    @GetMapping("/list")
    public TableDataInfo list(BizFamilyScoreLog bizFamilyScoreLog)
    {
        startPage();
        List<BizFamilyScoreLog> list = bizFamilyScoreLogService.selectBizFamilyScoreLogList(bizFamilyScoreLog);
        return getDataTable(list);
    }
    /**
     * 社区积分统计
     */
    @PreAuthorize("@ss.hasPermi('organization:family:list')")
    @PostMapping("/communityScore")
    public AjaxResult communityScore(@RequestBody CommunityScoreDto communityScoreDto)
    {
        CommunityScore score = bizFamilyScoreLogService.communityScore(communityScoreDto);
        return success(score);
    }
    /**
     * 导出家庭积分流水明细列表
     */
    @PreAuthorize("@ss.hasPermi('organization:familyScoreLog:export')")
    @Log(title = "家庭积分流水明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizFamilyScoreLog bizFamilyScoreLog)
    {
        List<BizFamilyScoreLog> list = bizFamilyScoreLogService.selectBizFamilyScoreLogList(bizFamilyScoreLog);
        ExcelUtil<BizFamilyScoreLog> util = new ExcelUtil<BizFamilyScoreLog>(BizFamilyScoreLog.class);
        util.exportExcel(response, list, "家庭积分流水明细数据");
    }

    /**
     * 获取家庭积分流水明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('organization:familyScoreLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizFamilyScoreLogService.selectBizFamilyScoreLogById(id));
    }

    /**
     * 新增家庭积分流水明细
     */
    @PreAuthorize("@ss.hasPermi('organization:familyScoreLog:add')")
    @Log(title = "家庭积分流水明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizFamilyScoreLog bizFamilyScoreLog)
    {
        bizFamilyScoreLog.setCreateBy(getUsername());
        return toAjax(bizFamilyScoreLogService.insertBizFamilyScoreLog(bizFamilyScoreLog));
    }

    /**
     * 修改家庭积分流水明细
     */
    @PreAuthorize("@ss.hasPermi('organization:familyScoreLog:edit')")
    @Log(title = "家庭积分流水明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizFamilyScoreLog bizFamilyScoreLog)
    {
        bizFamilyScoreLog.setUpdateBy(getUsername());
        return toAjax(bizFamilyScoreLogService.updateBizFamilyScoreLog(bizFamilyScoreLog));
    }

    /**
     * 删除家庭积分流水明细
     */
    @PreAuthorize("@ss.hasPermi('organization:familyScoreLog:remove')")
    @Log(title = "家庭积分流水明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizFamilyScoreLogService.deleteBizFamilyScoreLogByIds(ids));
    }
}
